<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    form{
      position: fixed;
      top:0; bottom:0;
      left:0; right:0;
      margin:auto;
      width:100px;
      height:200px;
      font-size: 20px;;
      border:1px solid #999;

    }
  </style>
</head>
<body>
  <form>
    全部:<input class="checkAll" type="checkbox"><br>
    选项1:<input class="checked" type="checkbox"><br>
    选项2:<input class="checked" type="checkbox"><br>
    选项3:<input class="checked" type="checkbox">
  </form>
</body>
</html>
<script>
  var checkAll = document.querySelector(".checkAll")
  var checked = document.querySelectorAll(".checked")
  checkAll.onclick = function(){
    var res = checkAll.checked
    for(var i=0;i<checked.length;i++){
      checked[i].checked = res;
    }
  }
  for(var i=0;i<checked.length;i++){
    checked[i].onclick = function(){
      for(var j=0;j<checked.length;j++){
        if(checked[j].checked !== true){
          checkAll.checked = false;
          break;
        }else{
          checkAll.checked = true;
        }
      }
    }
  }
</script>